package com.ljh.bigevent.controller;

import com.ljh.bigevent.pojo.Article;
import com.ljh.bigevent.pojo.PageBean;
import com.ljh.bigevent.pojo.Result;
import com.ljh.bigevent.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@Tag(name="文章模块")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping
        @Operation(summary = "添加文章接口")
    public Result add(@RequestBody @Validated(Article.Add.class) Article article) {
        return articleService.addArticle(article);
    }

    @GetMapping
        @Operation(summary = "分页接口")
    public Result<PageBean<Article>> list(@RequestParam Integer pageNum, @RequestParam Integer pageSize,
                                          @RequestParam(required = false) Integer categoryId,
                                          @RequestParam(required = false) String state) {
        return articleService.getArticleList(pageNum, pageSize, categoryId, state);
    }

    @PutMapping
        @Operation(summary = "更新文章接口")
    public Result update(@RequestBody @Validated(Article.Update.class) Article article) {
        return articleService.updateArticle(article);
    }

    @GetMapping("/detail")
        @Operation(summary = "根据id获取文章接口")
    public Result<Article> detail(@RequestParam Integer id) {
        return articleService.getArticleById(id);
    }

    @DeleteMapping
        @Operation(summary = "删除文章接口")
    public Result delete(@RequestParam Integer id) {
        return articleService.deleteArticle(id);
    }
}